package com.rxm.ys.controller;

import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.cloud.gateway.route.RouteDefinitionRepository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * @Description
 * @Author FengYi
 * @Date 2020-05-27 10:22
 */
@RestController
@RequestMapping("/route")
public class RouteController {

    private final RouteDefinitionRepository routeDefinitionRepository;

    public RouteController(RouteDefinitionRepository routeDefinitionRepository) {
        this.routeDefinitionRepository = routeDefinitionRepository;
    }

    @GetMapping("/list")
    public Flux<RouteDefinition> list(){
        return routeDefinitionRepository.getRouteDefinitions();
    }

    @GetMapping("/delete/{id}")
    public Mono<Void> flush(@PathVariable("id") String id){
        return routeDefinitionRepository.delete(Mono.just(id));
    }
}
